package com.j283_5.wisdom_park.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.j283_5.wisdom_park.common.result.ResultData;
import com.j283_5.wisdom_park.common.utils.FormatTool;
import com.j283_5.wisdom_park.mapper.OpelogmanageMapper;
import com.j283_5.wisdom_park.pojo.Opelogmanage;
import com.j283_5.wisdom_park.pojo.Project;
import com.j283_5.wisdom_park.service.OpelogmanageService;
import com.j283_5.wisdom_park.vo.confcenter_management.OpeLogManageVo;
import com.j283_5.wisdom_park.vo.confcenter_management.ProjectVo;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.sql.Timestamp;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author laoda
 * @since 2022-04-28
 */
@Service
public class OpelogmanageServiceImpl extends ServiceImpl<OpelogmanageMapper, Opelogmanage> implements OpelogmanageService {
    @Resource
    private OpelogmanageMapper opelogmanageMapper;

    @Override
    public ResultData opelogManage(Page<Opelogmanage> page, Opelogmanage opelogmanage) {
        if (page==null){
            page = new Page<>(1,10);
        }
        QueryWrapper<Opelogmanage> opelogmanageQueryWrapper=new QueryWrapper<>();
        opelogmanageQueryWrapper.orderByDesc("op_time");
        if (opelogmanage.getOpName()!=null){
            opelogmanageQueryWrapper.like("op_name",opelogmanage.getOpName());
        }
            opelogmanageQueryWrapper.orderByDesc("op_time");
        Page<Opelogmanage> opelogmanagePage=opelogmanageMapper.selectPage(page,opelogmanageQueryWrapper);
        if (opelogmanagePage!=null){
            return ResultData.ok().data(opelogmanagePage);
        }else {
            return ResultData.ok().data("查询失败!");
        }
    }

    @Override
    public ResultData addopeLogManage(OpeLogManageVo opeLogManageVo) {
        String opTime = opeLogManageVo.getOpTime();
        Date date = FormatTool.getDate(opTime, "yyyy-MM-dd HH:mm:ss");
        Opelogmanage opelogmanage=new Opelogmanage();
        BeanUtils.copyProperties(opeLogManageVo,opelogmanage);
        opelogmanage.setOpTime(new Timestamp(date.getTime()));
        int i=opelogmanageMapper.insert(opelogmanage);
        if (i>0){
            return ResultData.ok().message("添加成功!");
        }
        return ResultData.ok().message("添加失败!");
    }


}
